package com.heima.common.exception;


import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(ParamException.class)
    public ResponseResult exception(ParamException e) {
        log.error("catch exception:{}", e);
        return ResponseResult.error(e.getAppHttpCodeEnum());
    }

    @ExceptionHandler(LogicException.class)
    public ResponseResult exception(LogicException e) {
        log.error("catch exception:{}", e);
        return ResponseResult.error(e.getAppHttpCodeEnum());
    }

    @ExceptionHandler(CustomException.class)
    public ResponseResult exception(CustomException e) {
        log.error("catch exception:{}", e);
        return ResponseResult.error(e.getAppHttpCodeEnum());
    }

    @ExceptionHandler(Exception.class)
    public ResponseResult exception(Exception e) {
        e.printStackTrace();
        log.error("catch exception:{}", e.getMessage());
        return ResponseResult.error(AppHttpCodeEnum.SERVER_ERROR);
    }
}
